<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('巡检点列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <input type="hidden"  id="routeId" th:value="${routeId}" name="routeId"/>
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <p>巡检点id：</p>
                                <input type="text" name="inspectionId"/>
                            </li>
                            <li>
                                <p>名称：</p>
                                <input type="text" name="name"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "inspection/dian";

        $(function() {
            var options = {
                url: prefix + "/listDian?routeId="+$("#routeId").val(),
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "巡检点",
                columns: [{
                    checkbox: true
                },
                {
                    field : 'inspectionId', 
                    title : '巡检点id',
                },
                {
                    field : 'name', 
                    title : '巡逻点'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="choose(\'' + row.inspectionId + '\')"><i class="fa fa-plus"></i>增加</a> ');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        var ji=0;
        function ds(){
            ji=0;
        }
        function choose(id){
            if(ji==0){
                ji=1;
                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                //layer.msg(index);
                var routeId=$("#routeId").val();
                $.ajax({url:"/inspection/info/dianAdd",type:"post",data:"routeId="+routeId+"&inspectionId="+id,async:true,success:function (reslut) {
                        if (reslut.code=="0") {
                            layer.msg("添加成功", {icon: 1});
                            setTimeout(function(){
                                window.parent.location.reload();
                                parent.layer.close(index);
                                ds()
                            } ,1000)
                            //再执行关闭

                        }else{
                            ds()
                            layer.msg("添加失败", {icon: 2});
                        }

                    },error:function (reslut) {
                        ds()
                        layer.msg("操作失败", {icon: 2});
                    }
                });
            }else{

            }
        }
    </script>
</body>
</html>